package com.luoye.audiodemo

import android.Manifest.permission.CAMERA
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.PermissionUtils
import com.luoye.audiodemo.fragment.MyGLViewFragment
import com.luoye.audiodemo.fragment.MyGLViewFragment1
import com.luoye.audiodemo.fragment.MyGLViewFragment11
import com.luoye.audiodemo.fragment.MyGLViewFragment2
import com.luoye.audiodemo.fragment.MyGLViewFragment3
import com.luoye.audiodemo.fragment.MyGLViewFragment4
import com.luoye.audiodemo.fragment.MyGLViewFragment5
import com.luoye.audiodemo.fragment.MyGLViewFragment6
import com.luoye.audiodemo.fragment.MyGLViewFragment7
import com.luoye.audiodemo.fragment.MyGLViewFragment8
import com.luoye.audiodemo.fragment.MyGLViewFragment9

class MainActivity : AppCompatActivity() {
    val items = mutableListOf<ClickItem>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val listMain = findViewById<ListView>(R.id.listMain)
        initData()
        listMain.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, items)
        listMain.setOnItemClickListener { _, _, i, _ ->
            items[i].onClick()
        }
    }

    private fun initData() {
        items += ClickItem("openGL 绘制红色区域") {
            openFragment(MyGLViewFragment::class.java.name)
        }
        items += ClickItem("openGL 绘制红色区域1") {
            openFragment(MyGLViewFragment1::class.java.name)
        }
        items += ClickItem("openGL 基于EGL协议 自定义 SurfaceView") {
            openFragment(MyGLViewFragment2::class.java.name)
        }
        items += ClickItem("openGL 绘制3角形") {
            openFragment(MyGLViewFragment3::class.java.name)
        }
        items += ClickItem("openGL 绘制菱形") {
            openFragment(MyGLViewFragment4::class.java.name)
        }
        items += ClickItem("openGL 绘制圆") {
            openFragment(MyGLViewFragment5::class.java.name)
        }
        items += ClickItem("openGL demo 绘制") {
            openFragment(MyGLViewFragment6::class.java.name)
        }
        items += ClickItem("openGL GLSurfaceView 绘制基本形状") {
            openFragment(MyGLViewFragment7::class.java.name)
        }
        items += ClickItem("openGL GLSurfaceView 绘制王冰冰") {
            openFragment(MyGLViewFragment8::class.java.name)
        }
        items += ClickItem("openGL GLSurfaceView 绘制nbb2") {
            openFragment(MyGLViewFragment11::class.java.name)
        }
        items += ClickItem("openGL 相机1") {
            PermissionUtils.permission(CAMERA).callback({ isAllGranted, granted, deniedForever, denied ->
                openFragment(MyGLViewFragment9::class.java.name)
            }).request()

        }
        items += ClickItem("openGL 相机2") {
            PermissionUtils.permission(CAMERA).callback({ isAllGranted, granted, deniedForever, denied ->
                openFragment(MyGLViewFragment9::class.java.name)
            }).request()

        }
    }

}